#pragma once

#include <iostream>
#include <string>
#include <functional>

using namespace std;

// typedef function<void *(void *)> func_t;
typedef void *(*func_t)(void *);

class ThreadData
{
public:
    void *_args;
    string _name;
};

class Thread
{
public:
    Thread(int num, func_t callback, void *args)
        : _func(callback)
    {
        char nameBuff[64];
        snprintf(nameBuff, sizeof(nameBuff), "Thread-%d", num);
        _name = nameBuff;

        _tdata._args = args;
        _tdata._name = _name;
    }

    void start()
    {
        pthread_create(&_tid, nullptr, _func, (void *)&_tdata);
    }
    void join()
    {
        pthread_join(_tid, nullptr);
    }
    string name()
    {
        return _name;
    }

private:
    string _name;
    pthread_t _tid;
    func_t _func;
    ThreadData _tdata;
};